namespace CSharpPro._1027;


public class UserServiceImpl : UserService
{
    // 模拟存储用户的字典
    private Dictionary<int, string> _userDict = new Dictionary<int, string>();
    private int _idGenerator = 1;

    public void AddUser(string username, string password)
    {
        _userDict.Add(_idGenerator, $"{username},{password}");
        _idGenerator++;
        System.Console.WriteLine("用户添加成功");
    }

    public void DeleteUser(int userId)
    {
        if (_userDict.ContainsKey(userId))
        {
            _userDict.Remove(userId);
            System.Console.WriteLine("用户删除成功");
        }
        else
        {
            System.Console.WriteLine("用户不存在，删除失败");
        }
    }

    public void UpdateUser(int userId, string newPassword)
    {
        if (_userDict.ContainsKey(userId))
        {
            string[] userInfo = _userDict[userId].Split(',');
            _userDict[userId] = $"{userInfo[0]},{newPassword}";
            System.Console.WriteLine("用户密码修改成功");
        }
        else
        {
            System.Console.WriteLine("用户不存在，修改失败");
        }
    }

    public string QueryUser(int userId)
    {
        if (_userDict.ContainsKey(userId))
        {
            return "用户信息：" + _userDict[userId];
        }
        else
        {
            return "用户不存在";
        }
    }
}
